//
//  MeasureViewController.m
//  Romens.XSBalance
//
//  Created by 李美东 on 16/2/23.
//  Copyright © 2016年 孙博. All rights reserved.
//

#import "MeasureViewController.h"
#import "ToolHelper.h"
#import "SSBLEDeviceManager.h"
#import "AppDelegate.h"
#import "BodyMeasure.h"
#import "CBPeripheralAdditions.h"
#import "TestResultCell.h"
#import "BMITestCell.h"
#import "Unit.h"
#import "TestResult.h"
#import "MJExtension.h"
#import "MyViewController.h"
#import "RuntimeStatus.h"
#import "userInformation.h"
#import "DataDBManager.h"
#import "WebRequest.h"
#import "WebRequestData.h"
#import "GetCurrentTime.h"
#import "usertestInformation.h"
@interface MeasureViewController ()<UITableViewDataSource, UITableViewDelegate>
{
    BOOL _isConnected;
    BOOL _isAllowWrite;
    NSTimer *_sendTimer;
    NSInteger _sendType;
    UITableView *_tableView;
    NSMutableArray *_nameArray;
    NSMutableArray *_showImageArray;
    NSMutableArray * _testResultArray;
    NSString* weightString;//测量体重结果；
    float _BmiValue;
    BOOL _allowWriteNewValue;
}
@end

@implementation MeasureViewController
- (id)init {
    self = [super init];
    if (self) {
        _isConnected = NO;
        _isAllowWrite = YES;
    }
    return self;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    [self initView];
    UIBarButtonItem *rightButton = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"保存", nil) style:UIBarButtonItemStylePlain target:self action:@selector(save)];
    self.navigationItem.rightBarButtonItem = rightButton;
    
    _nameArray=[NSMutableArray arrayWithObjects:@"BMI",@"脂肪率",@"骨骼值",@"水分值",@"肌肉值",@"卡路里", nil];
    UIImage *image1=[UIImage imageNamed:@"脂肪率"];
    UIImage *image2=[UIImage imageNamed:@"bones"];
    UIImage *image3=[UIImage imageNamed:@"水分值"];
    UIImage *image4=[UIImage imageNamed:@"muscle"];
    UIImage *image5=[UIImage imageNamed:@"calorie"];
    UIImage *image6=[UIImage imageNamed:@"BMI"];
    _showImageArray=[NSMutableArray arrayWithObjects:image6,image1,image2,image3,image4,image5, nil];
  //TODO:暂时屏蔽，看看效果；
    [self currentUserChangeNotification:nil];
//    NSString* string=@"00.0  kg";
//    NSMutableAttributedString *attrString =
//    [[NSMutableAttributedString alloc] initWithString:string];
//    UIFont *boldFont = systemFont(30.0);
//    NSUInteger length = [string length];
//    [attrString addAttribute:NSFontAttributeName value:boldFont
//                       range:NSMakeRange(2,length-2)];
//    _showLabel.attributedText=attrString;
    
    _testResultArray=[[NSMutableArray alloc]init];
    //通知，添加设备；
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(addDevices:) name:@"addDevices" object:nil];
    //通知，当前用户改变；
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(currentUserChangeNotification:) name:@"CurrentUserChange" object:nil];
}
-(void)dealloc
{
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}

# pragma mark -当前用户改变；
-(void)currentUserChangeNotification:(NSNotification*)notify
{
    userInformation* currentInfo=[RuntimeStatus instance].CurrUser;
    
    
    _targetWeightLabel.text=[NSString stringWithFormat:@"%@%@ %@",NSLocalizedString(@"目标体重", nil),currentInfo.TarghtWeight,currentInfo.WEIGHT_UNIT];
    __50kgLabel.text=[NSString stringWithFormat:@"%@ %@",currentInfo.TarghtWeight,currentInfo.WEIGHT_UNIT];
    if (_testResultArray.count!=0)
    {
        [_testResultArray removeAllObjects];
        [_tableView reloadData];
    }
    NSString* string=@"00.0  KG";
    if ([currentInfo.WEIGHT_UNIT isEqualToString:@"LB"]) {
        string=@"00.0  LB";
    }
    NSMutableAttributedString *attrString =
    [[NSMutableAttributedString alloc] initWithString:string];
    UIFont *boldFont = systemFont(30.0);
    NSUInteger length = [string length];
    [attrString addAttribute:NSFontAttributeName value:boldFont
                       range:NSMakeRange(length-6,6)];
    _showLabel.attributedText=attrString;
}
# pragma mark -添加设备；
-(void)addDevices:(NSNotification*)notify
{
    NSDictionary * dic=notify.object;
    _deviceName=[dic objectForKey:@"name"];
    _deviceID=[dic objectForKey:@"deviceID"];
    _advertiseName=[dic objectForKey:@"advertiseName"];
    _serialNO=[dic objectForKey:@"serialNO"];
    
}
#pragma mark--所有控件初始化；
-(void)initView
{
    UIView * backView=[[UIView alloc]initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.width-40)];
    _tableView = [[UITableView alloc]init];
    _tableView.translatesAutoresizingMaskIntoConstraints=NO;
    _tableView.dataSource = self;
    _tableView.delegate = self;
    _tableView.bounces = NO;
    _tableView.showsHorizontalScrollIndicator = NO;
    _tableView.showsVerticalScrollIndicator = NO;
    _tableView.tableHeaderView=backView;
    [self.view addSubview:_tableView];
    

    [self.view addConstraints:[ToolHelper GetNSLayoutCont:NSDictionaryOfVariableBindings(_tableView)  format:@"H:|[_tableView]|"]];
    [self.view addConstraints:[ToolHelper GetNSLayoutCont:NSDictionaryOfVariableBindings(_tableView)  format:@"V:|[_tableView]|"]];
    
    UIView *backView1 =[[UIView alloc]init];
    backView1.translatesAutoresizingMaskIntoConstraints=NO;
    [backView addSubview:backView1];
    [backView addConstraints:[ToolHelper GetNSLayoutCont:NSDictionaryOfVariableBindings(backView1)  format:@"H:|-40-[backView1]-40-|"]];
    [backView addConstraints:[ToolHelper GetNSLayoutCont:NSDictionaryOfVariableBindings(backView1)  format:@"V:|-40-[backView1]|"]];
    
    _warningLabel=[[UILabel alloc]init];
    _warningLabel.translatesAutoresizingMaskIntoConstraints=NO;
    [_warningLabel sizeToFit];
    _warningLabel.textColor=[UIColor grayColor];
    [backView addSubview:_warningLabel];
    
    _bindButton =[UIButton buttonWithType:UIButtonTypeRoundedRect];
    _bindButton.translatesAutoresizingMaskIntoConstraints=NO;
    [_bindButton setTitle:NSLocalizedString(@"绑定",nil) forState:UIControlStateNormal];
    [_bindButton addTarget:self action:@selector(bingDevice) forControlEvents:UIControlEventTouchUpInside];
    _bindButton.hidden=YES;
    [backView addSubview:_bindButton];

    [backView addConstraints:[ToolHelper GetNSLayoutCont:NSDictionaryOfVariableBindings(_warningLabel)  format:@"H:|-8-[_warningLabel(120)]"]];
    [backView addConstraints:[ToolHelper GetNSLayoutCont:NSDictionaryOfVariableBindings(_bindButton)  format:@"H:[_bindButton(60)]-8-|"]];
    [backView addConstraints:[ToolHelper GetNSLayoutCont:NSDictionaryOfVariableBindings(_warningLabel)  format:@"V:|-8-[_warningLabel(30)]"]];
    [backView addConstraints:[ToolHelper GetNSLayoutCont:NSDictionaryOfVariableBindings(_bindButton)  format:@"V:|-8-[_bindButton(30)]"]];
    //背景图片；
    _backImage=[[UIImageView alloc]init];
    _backImage.translatesAutoresizingMaskIntoConstraints=NO;
    _backImage.image=[UIImage imageNamed:@"scaleClock"];
    [backView1 addSubview:_backImage];
    
    //背景图片 加限制；
    [backView1 addConstraints:[ToolHelper GetNSLayoutCont:NSDictionaryOfVariableBindings(_backImage)  format:@"H:|[_backImage]|"]];
    [backView1 addConstraints:[ToolHelper GetNSLayoutCont:NSDictionaryOfVariableBindings(_backImage)  format:@"V:|[_backImage]|"]];
    
    _targetImage=[[UIImageView alloc]init];
    _targetImage.translatesAutoresizingMaskIntoConstraints=NO;
    _targetImage.image=[UIImage imageNamed:@"target"];
    [backView1 addSubview:_targetImage];
    
    //体重；
    _weightLabel=[[UILabel alloc]init];
    _weightLabel.translatesAutoresizingMaskIntoConstraints=NO;
    _weightLabel.text=NSLocalizedString(@"体重", nil);
    _weightLabel.textAlignment=NSTextAlignmentCenter;
    _weightLabel.font=systemFont(18);
    _weightLabel.textColor=[UIColor whiteColor];
    [backView1 addSubview:_weightLabel];
    
    //显示体重label；
    _showLabel=[[UILabel alloc]init];
    _showLabel.translatesAutoresizingMaskIntoConstraints=NO;
    _showLabel.font=systemFont(60);
    _showLabel.textAlignment=NSTextAlignmentRight;
    _showLabel.textColor=[UIColor whiteColor];
    [backView1 addSubview:_showLabel];
    
    //50.0kg
    __50kgLabel=[[UILabel alloc]init];
    __50kgLabel.translatesAutoresizingMaskIntoConstraints=NO;
    __50kgLabel.textAlignment=NSTextAlignmentRight;
    __50kgLabel.textColor=[UIColor whiteColor];
    [backView1 addSubview:__50kgLabel];
    
    //目标体重；
    _targetWeightLabel=[[UILabel alloc]init];
    _targetWeightLabel.translatesAutoresizingMaskIntoConstraints=NO;
    _targetWeightLabel.font=systemFont(18);
    _targetWeightLabel.textAlignment=NSTextAlignmentCenter;
    _targetWeightLabel.textColor=[UIColor whiteColor];
    [backView1 addSubview:_targetWeightLabel];
    
    //图片上所有的label加限制；
    [backView1 addConstraints:[ToolHelper GetNSLayoutCont:NSDictionaryOfVariableBindings(_weightLabel)  format:@"H:[_weightLabel(60)]"]];
    [backView1 addConstraint:[NSLayoutConstraint constraintWithItem:_weightLabel
                                                          attribute:NSLayoutAttributeCenterX
                                                          relatedBy:NSLayoutRelationEqual
                                                             toItem:backView1                                             attribute:NSLayoutAttributeCenterX
                                                         multiplier:1.0f
                                                           constant:0]];
    
    [backView1 addConstraints:[ToolHelper GetNSLayoutCont:NSDictionaryOfVariableBindings(_showLabel,_backImage)  format:@"H:[_showLabel(200)]-20-|"]];
    
    [backView1 addConstraints:[ToolHelper GetNSLayoutCont:NSDictionaryOfVariableBindings(_targetImage,__50kgLabel)  format:@"H:[_targetImage(15)][__50kgLabel(60)]"]];
    [backView1 addConstraint:[NSLayoutConstraint constraintWithItem:__50kgLabel
                                                          attribute:NSLayoutAttributeCenterX
                                                          relatedBy:NSLayoutRelationEqual
                                                             toItem:backView1                                             attribute:NSLayoutAttributeCenterX
                                                         multiplier:1.0f
                                                           constant:0]];
    
    [backView1 addConstraints:[ToolHelper GetNSLayoutCont:NSDictionaryOfVariableBindings(_targetWeightLabel)  format:@"H:[_targetWeightLabel(150)]"]];
    [backView1 addConstraint:[NSLayoutConstraint constraintWithItem:_targetWeightLabel
                                                          attribute:NSLayoutAttributeCenterX
                                                          relatedBy:NSLayoutRelationEqual
                                                             toItem:backView1                                             attribute:NSLayoutAttributeCenterX
                                                         multiplier:1.0f
                                                           constant:0]];
    
    [backView1 addConstraints:[ToolHelper GetNSLayoutCont:NSDictionaryOfVariableBindings(_backImage,_weightLabel,_showLabel,__50kgLabel,_targetWeightLabel)  format:@"V:|-60-[_weightLabel(20)]-[_showLabel(54)]-10-[__50kgLabel(20)][_targetWeightLabel(30)]"]];
    [backView1 addConstraints:[ToolHelper GetNSLayoutCont:NSDictionaryOfVariableBindings(_targetImage)  format:@"V:[_targetImage(15)]"]];
    [backView1 addConstraint:[NSLayoutConstraint constraintWithItem:_targetImage
                                                          attribute:NSLayoutAttributeCenterY
                                                          relatedBy:NSLayoutRelationEqual
                                                             toItem:__50kgLabel                                             attribute:NSLayoutAttributeCenterY
                                                         multiplier:1.0f
                                                           constant:0]];
    
}
# pragma mark -绑定设备；
-(void)bingDevice
{
    [self.tabBarController setSelectedIndex:2];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}
- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
     AppDelegate *delegate = [UIApplication sharedApplication].delegate;
    if (_deviceName==nil ||[_deviceName isEqualToString:@""]) {
        _warningLabel.text=NSLocalizedString(@"未绑定", nil);
        _bindButton.hidden=NO;
    }
    else
    {
        _warningLabel.text=_deviceName;
        _bindButton.hidden=YES;
    }

    if ((self.serialNO!=nil) && (self.advertiseName!=nil)) {
        //[delegate.bleMgr connect:@{self.deviceID: self.advertiseName}];
        [delegate.bleMgr connectWithSerialNO:@{self.serialNO: self.advertiseName}];
        
    }
    [delegate.bleMgr addDelegate:self];
    [delegate.bleMgr scanPeripherals];
    
    [self currentUserChangeNotification:nil];
}
# pragma mark -计算当前用户的身体年龄；
-(int)calculateAge:(NSString*)string
{
    NSArray * array=[string componentsSeparatedByString:@"-"];
    int userYear=[[array objectAtIndex:0] intValue];
    int userMonth=[[array objectAtIndex:1] intValue];
    int userDay=[[array objectAtIndex:2] intValue];
    
    NSDate *nowDate = [NSDate date];
    NSCalendar *calendar = [NSCalendar currentCalendar];
    NSUInteger unitFlags = NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit;
    NSDateComponents *dateComponent = [calendar components:unitFlags fromDate:nowDate];
    int nowDay =(int)[dateComponent day];
    int nowMonth=(int)[dateComponent month];
    int nowYear=(int)[dateComponent year];
    
    int ageYear=nowYear-userYear;
    int ageMonth=nowMonth-userMonth;
    int ageDay=nowDay-userDay;
    if (ageYear>0)
    {
        if (ageMonth<0)
        {
            ageYear=ageYear-1;
        }
        else if(ageMonth==0)
        {
            if (ageDay<0) {
                ageYear=ageYear-1;
            }
        }
    }
    else
    {
        ageYear=0;
    }
    return ageYear;
}
- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    
    AppDelegate *delegate = [UIApplication sharedApplication].delegate;
    [delegate.bleMgr disconnectWithSerialNO:self.serialNO];
    [delegate.bleMgr removeDelegate:self];
}

#pragma mark--健康秤 delegate
//已连接设备；
- (void)peripheralDidConnect:(CBPeripheral *)peripheral {
    _allowWriteNewValue=YES;
    _isConnected = YES;
    dispatch_async(dispatch_get_main_queue(), ^(void){
        
    });
}
//设备连接断开；
- (void)peripheralDidDisconnect:(CBPeripheral *)peripheral {
    _isConnected = NO;
    _isAllowWrite = NO;
    dispatch_async(dispatch_get_main_queue(), ^(void){
    });
}
//设备允许写入信息；
- (void)peripheralDidAllowWrite:(CBPeripheral *)peripheral {
    _isAllowWrite = YES;
    
    [self testFat];
}
# pragma mark -设备写入信息，准备测试体脂；
-(void)testFat
{
    AppDelegate *delegate = [UIApplication sharedApplication].delegate;
    CBPeripheral *peripheral2 = delegate.bleMgr.deviceIDToPeripheralMap.allValues.lastObject;
    
    userInformation* currentInfo=[RuntimeStatus instance].CurrUser;
    int sex=[currentInfo.SEX intValue] ;

    Unit *unitHeight = [[Unit getHeightUnitDictionary] objectForKey:@"in"];
    NSString *height=currentInfo.Height;
    int heightCM;
    int heightInch;
    if ([currentInfo.HEIGHT_UNIT isEqualToString:@"CM"]) {
        heightCM=[height intValue];
        heightInch = heightCM * unitHeight.ExchangeRate;
    }
    else
    {
        heightInch=[height intValue];
        heightCM=heightInch/unitHeight.ExchangeRate;
    }
    
    
    int age=[self calculateAge:currentInfo.Birthday];
    [delegate.bleMgr sendSENSSUNFATTestFatWithSex:sex userID:2  age:age heightCM:heightCM heightInch:heightInch * 10 peripheral:peripheral2];
}
# pragma mark -从健康秤获取数据；
-(void)peripheralDidReceived:(CBPeripheral *)peripheral value:(BodyMeasure *)value values:(NSMutableArray *)values
{
    if(_allowWriteNewValue==YES)
    {
    dispatch_async(dispatch_get_main_queue(), ^(void)
                   {
                       
                    
                       if ((value.bodyMassKG/ 10.0f)<10) {
                          weightString=[NSString stringWithFormat:@"0%.1f", value.bodyMassKG / 10.0f];
                       }
                       else
                       {
                       weightString=[NSString stringWithFormat:@"%.1f", value.bodyMassKG / 10.0f];
                       }
                       
                       userInformation* currentInfo=[RuntimeStatus instance].CurrUser;
                       Unit *unitWeight = [[Unit getWeightUnitDictionary] objectForKey:@"lb"];
                       NSString *weightUnitString=[NSString stringWithFormat:@"%@  KG",weightString];
                       if ([currentInfo.WEIGHT_UNIT isEqualToString:@"LB"]) {
                           double weight =[weightString doubleValue];
                           weightString=[NSString stringWithFormat:@"%.1f",weight*unitWeight.ExchangeRate];
                           if ( (weight*unitWeight.ExchangeRate)<10.0) {
                               weightUnitString=[NSString stringWithFormat:@"0%@  LB",weightString];
                           }
                           else
                           {
                           weightUnitString=[NSString stringWithFormat:@"%@  LB",weightString];
                           }

                       }
                       NSUInteger length = [weightUnitString length];
                       NSMutableAttributedString *attrString =
                       [[NSMutableAttributedString alloc] initWithString:weightUnitString];
                       UIFont *boldFont = systemFont(30.0);
                       [attrString addAttribute:NSFontAttributeName value:boldFont
                                          range:NSMakeRange(length-6,6)];
                       _showLabel.attributedText=attrString;
                       
                       
                       if (value.ifStable==NO && _testResultArray.count!=0)
                       {
                           [_testResultArray removeAllObjects];
                       }
                       if (value && value.dataType == DatatypeTestFat)
                       {
                           NSString * lblFat = [NSString stringWithFormat:@"%.1f %%", value.bodyFatPercentage / 10.f];
                           NSString * lblHydration = [NSString stringWithFormat:@"%.1f %%", value.hydro / 10.f];
                           NSString * lblMuscle = [NSString stringWithFormat:@"%.1f %%", value.muscle / 10.f];
                           NSString * lblBone = [NSString stringWithFormat:@"%.1f %%", value.bone / 10.f];
                           NSString * lblKcal = [NSString stringWithFormat:@"%d kcal", value.kcal];
                           
                           userInformation* currentInfo=[RuntimeStatus instance].CurrUser;
                           Unit *unitHeight = [[Unit getHeightUnitDictionary] objectForKey:@"in"];
                           NSString *height=currentInfo.Height;
                           int heightCM;
                           
                           if ([currentInfo.HEIGHT_UNIT isEqualToString:@"CM"]) {
                               heightCM=[height intValue];
                           }
                           else
                           {
                               int heightInch=[height intValue];
                               heightCM=heightInch/unitHeight.ExchangeRate;
                           }
                           _BmiValue=(value.bodyMassKG/10.0f)/(heightCM*heightCM/10000.0f);
                           
                           _testResultArray=[NSMutableArray arrayWithObjects:[NSString stringWithFormat:@"%.2lf",_BmiValue],lblFat,lblBone,lblHydration,lblMuscle,lblKcal, nil];
                          _allowWriteNewValue=NO;
                       }
                       [_tableView reloadData];
                   });
    }
}
# pragma mark -数据存储
// 测量结束后 点击保存按钮，数据存储；
-(void)save
{
    int weightInt = [weightString intValue];
    NSLog(@"%i",weightInt);
    if (weightInt==0) {
        return;
    }
    NSString * timeString=[GetCurrentTime currentTime];
    NSArray * date=[timeString componentsSeparatedByString:@" "];
    userInformation* currentInfo=[RuntimeStatus instance].CurrUser;
    usertestInformation * testInfo = [usertestInformation new];
    testInfo.HEALTHTYPE=@"健康秤";
    testInfo.USERID=currentInfo.USERID;
    testInfo.Weight=weightString;
    if (_testResultArray.count!=0)
    {
    testInfo.BMI=[_testResultArray objectAtIndex:0];
    testInfo.Fat=[_testResultArray objectAtIndex:1];
    testInfo.Bones=[_testResultArray objectAtIndex:2];
    testInfo.Water=[_testResultArray objectAtIndex:3];
    testInfo.Muscle=[_testResultArray objectAtIndex:4];
    testInfo.Calorie=[_testResultArray objectAtIndex:5];
    }
    testInfo.CreateDate=[date firstObject];
    testInfo.CreateTime=[date lastObject];
    testInfo.TestUnit=currentInfo.WEIGHT_UNIT;

        DataDBManager * manager=[DataDBManager new];
    [manager InsertUserTestData:testInfo suessblock:^(NSString* result){
        [self showHint:@"测量数据已保存"];
    
    }];
}
# pragma mark -通过BMI数据，判断健康状况；
-(NSString *)calculateHealthScore:(float)bmiValue
{
    if (bmiValue<18.5) {
        return @"过轻";
    }
    else if(bmiValue>=18.5 && bmiValue<25)
    {
        return @"正常";
    }
    else if (bmiValue>=25 && bmiValue<28)
    {
        return @"过重";
    }
    else if(bmiValue>=28 && bmiValue<=32)
    {
        return @"肥胖";
    }
    else if (bmiValue>32)
    {
        return @"非常肥胖";
    }
    return nil;
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 6;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 40;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *identifier = @"TestResultCell";
    TestResultCell *testCell = [tableView dequeueReusableCellWithIdentifier:identifier];
    if (testCell == nil)
    {
        testCell = [[TestResultCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
    }
    testCell.selectionStyle = UITableViewCellSelectionStyleNone;
    static NSString *identifierBMI = @"bmiCell";
    BMITestCell *bmiCell = [tableView dequeueReusableCellWithIdentifier:identifierBMI];
    if (bmiCell == nil)
    {
        bmiCell = [[BMITestCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
    }
    bmiCell.selectionStyle = UITableViewCellSelectionStyleNone;
    switch (indexPath.row)
    {
        case 0:
        {
            if (_testResultArray.count==0) {
                bmiCell.showValueLabel.text=@"--";
                bmiCell.healthScore.text=@" ";
            }
            else
            {
                bmiCell.showValueLabel.text=[_testResultArray firstObject];
                bmiCell.healthScore.text=NSLocalizedString([self calculateHealthScore:_BmiValue], nil);
            }
            bmiCell.showImage.image=[_showImageArray objectAtIndex:indexPath.row];
            NSString * string=[_nameArray objectAtIndex:indexPath.row];
            bmiCell.nameLabel.text=NSLocalizedString(string, nil);
            return bmiCell;
        }
            break;
        default:
        {
            if (_testResultArray.count==0) {
                testCell.showValueLabel.text=@"--";
            }
            else
            {
                testCell.showValueLabel.text=[_testResultArray objectAtIndex:indexPath.row];
            }
            testCell.showImage.image=[_showImageArray objectAtIndex:indexPath.row];
            NSString * string=[_nameArray objectAtIndex:indexPath.row];
            testCell.nameLabel.text=NSLocalizedString(string, nil);
            return testCell;
        }
            break;
    }
}

@end
